package com.shilan.dllo.wangyi.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.shilan.dllo.wangyi.R;
import com.shilan.dllo.wangyi.adpter.TabLayoutFragmentAdpter;

/**
 * Created by dllo on 15/10/22.
 */
public class NewsFragment  extends Fragment{

    private RequestQueue queue;
    private RecyclerView newsView;

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private TabLayoutFragmentAdpter adapter;

    private  Context context;
    private int position;


    public static final String ARGS_POSITION = "position";

    public static NewsFragment newInstance(int position){
        NewsFragment f = new NewsFragment();
        Bundle args = new Bundle();
        args.putInt(ARGS_POSITION, position);
        f.setArguments(args);
        return f;
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_news,null);
        return view;
    }

    /**
     * 初始化控件 对tablayout进行设置
     * viewpager绑定适配器
     * tablayout和viewpage的绑定
     * @param view
     * @param savedInstanceState
     */
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager);
        adapter = new TabLayoutFragmentAdpter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
       // initView();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

//    private void initView() {
//        queue = Volley.newRequestQueue(getContext());
//        newsView = (RecyclerView) getActivity().findViewById(R.id.newsRecyclerView);
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),1);
//        newsView.setLayoutManager(gridLayoutManager);
//
//    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            position = args.getInt(ARGS_POSITION);
        }
    }
}
